package com.example.springbootfirst.api;

import com.example.springbootfirst.dto.ResponseDto;
import com.example.springbootfirst.exception.BaseException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * created by Morgan on 2021/9/30
 */
@RestController
@RequestMapping(value = "/api/v1/demo")
@Api(tags = "【demo controller】")
@Slf4j
public class DemoController {
    @Value("${server.port}")
    private String name;

    @GetMapping(value = "/sayHello")
    @ApiOperation("sayHello方法")
    public String sayHello() {
        return "hello,this is my demo" + name;
    }
    @GetMapping(value = "/sayError")
    @ApiOperation("sayError方法")
    public String sayError() {
        throw new BaseException("500","程序报错了");
    }

    @GetMapping(value = "/sayParam/{param}")
    @ApiOperation("sayParam方法")
    @ApiParam
    public ResponseDto<String> sayParam(@PathVariable String param) {
        return ResponseDto.getSuccessResponseDto(param);
    }

}
